package com.hrpmar.service.impl;

import com.hrpmar.controller.dto.PurplanDto;
import com.hrpmar.mapper.DestorydetailsMapper;
import com.hrpmar.mapper.DestorymasterMapper;
import com.hrpmar.mapper.PurplanMapper;
import com.hrpmar.pojo.Destorydetails;
import com.hrpmar.pojo.Destorymaster;
import com.hrpmar.service.AuditService;
import com.hrpmar.utils.Pager;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by c on 2017-11-20.
 */
@Service
@Transactional
public class AuditServiceImpl implements AuditService {
    @Resource
    private PurplanMapper purplanMapper;

    @Resource
    private DestorymasterMapper destorymasterMapper;

    @Resource
    private DestorydetailsMapper destorydetailsMapper;

    @Override
    public Pager search(Integer offset, Integer limit, PurplanDto condition) {
        condition.setPurState("true");
        Pager pager = new Pager();
        pager.setRows(purplanMapper.searchPurPlanByCondition(offset,limit,condition));
        pager.setTotal(purplanMapper.getTotal(condition));
        return pager;
    }

    @Override
    public void auditPurplan(String planNum, Integer planChstate, String planViews) {
        purplanMapper.auditPurplan(planNum,planChstate,planViews);
    }

    @Override
    public Pager searchPendingAudit(PurplanDto dto,Integer offset, Integer limit) {
        Pager pager = new Pager();
        List<Destorymaster> list = destorymasterMapper.searchPendingAudit(dto,offset,limit);
        Integer total = destorymasterMapper.totalAudit(dto);
        pager.setRows(list);
        pager.setTotal(total);
        return pager;
    }

    @Override
    public List<Destorydetails> searchDan(String desNum) {
        return destorydetailsMapper.searchMasterDan(desNum);
    }

    @Override
    public void auditDestorymaster(String desNum, Integer desAuditstate, String desViews) {
        destorymasterMapper.updateExamine(desAuditstate,desViews,desNum);
    }
}
